package com.wnxy.service;

import com.wnxy.dto.StatusCode;
import com.wnxy.exception.LoginException;
import com.wnxy.exception.OrderException;
import com.wnxy.vo.OrderValideVo;
import com.wnxy.vo.OrderVo;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;


@Aspect
@Service
public class BuyValidateService {
    @Autowired
    private StringRedisTemplate srt;
    @Before("@annotation(com.wnxy.annotation.BuyValidate)")
    public void before(JoinPoint jp ) throws LoginException {
        OrderVo orderVo = (OrderVo) jp.getArgs()[0];
        String s = srt.opsForValue().get("wnxy:theater:user:" + orderVo.getOrderTel());
        if(s==null||"".equals(s)) throw new OrderException(StatusCode.ORDERERROR.getCode(), "请先获取验证码");
    }
}
